public class Trie {
    public int p;
    public int end;
    public Trie[] next;

    public Trie() {
        next = new Trie[26];
    }

    public void insert(String word) {
        char[] words = word.toCharArray();
        Trie node = null;
        node = this;
        for (int i = 0; i < words.length; i++) {
            int index = words[i] - 'a';
            if (node.next[index] == null) {
                node.next[index] = new Trie();
            }
            node = node.next[index];
            node.p++;
        }
        node.end++;
    }

    public boolean search(String word) {
        char[] words = word.toCharArray();
        Trie node = this;
        for (int i = 0; i < words.length; i++) {
            int index = words[i] - 'a';
            if (node.next[index] == null) {
                return false;
            } else {
                node = node.next[index];
            }
        }
        if (node.end == 0) return false;
        return true;
    }

    public boolean startsWith(String prefix) {
        char[] words = prefix.toCharArray();
        Trie node = this;
        for (int i = 0; i < words.length; i++) {
            int index = words[i] - 'a';
            if (node.next[index] == null) {
                return false;
            } else {
                node = node.next[index];
            }
        }
        return true;
    }
}

class Test {
    private static volatile Test test;

    private Test() {}

    public static Test getInstance() {
        if (test == null) {
            synchronized (Test.class) {
                if (test == null) {
                    test = new Test();
                }
            }
        }
        return test;
    }

    public void process() {
        System.out.println("运行!");
    }

    public static void main(String[] args) {
        for (int i = 0; i < 1000; i++) {
            new Thread(() -> {
                Test instance = Test.getInstance();
                instance.process();
            }).start();
        }
    }
}
